// 管理账号信息
//写入状态
let iswrite = false;
let listData = []


const tapNav = function (e) {
	uni.redirectTo({
		url: e,
		success: res => {},
		fail: () => {},
		complete: () => {}
	});
}

const navTo = function (e) {
	uni.navigateTo({
		url: e,
		success: res => {},
		fail: () => {},
		complete: () => {}
	});
}

const switechNav = function (e) {
	uni.switchTab({
		url: e,
		success: res => {},
		fail: () => {},
		complete: () => {}
	});
}

const getRequest = function (_e,_method,_data) {
	uni.request({
		url: _e,
		method: _method,
		data: _data,
		success: res => {
			if (res.data.data.code == 200) {
				iswrite = true
			}
		},
		fail: () => {},
		complete: () => {}
	});
}

const Request = function (_e,_method,_data) {
	uni.request({
		url: _e,
		method: _method,
		data: _data,
		success: res => {
			// console.log(res)
			if (res.data.data.code == 200) {
				listData = res.data.data
			}
		},
		fail: () => {},
		complete: () => {}
	});
}


const getSystemInfo = function (){
	//获取手机型号
	wx.getSystemInfo({
		success(res) {
			const model = res.model;
			const modelInclude = ['iPhone X', 'iPhone XR', 'iPhone XS', 'iPhone XS MAX'];
			var flag = false; //是否X以上机型
			for (let i = 0; i < modelInclude.length; i++) {
				//模糊判断是否是modelInclude 中的机型,因为真机上测试显示的model机型信息比较长无法一一精确匹配
				if (model.indexOf(modelInclude[i]) != -1) {
					flag = true;
				}
			}
			if (flag) {
				uni.setStorageSync('model',true)
				// that.BOTTOM_DISTANCE = true;
			}else{
				uni.setStorageSync('model',false)
			}
		}
	});
}



const formatTime  = function(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  // var hour = date.getHours()
  // var minute = date.getMinutes()
  // var second = date.getSeconds()
  return year + month + day;
}


export default {
    tapNav,
    getRequest,
	Request,
	iswrite,
	listData,
	switechNav,
	navTo,
	getSystemInfo,
	formatTime
}
